using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using MyWebApi.Api.Entity;
using System.Linq;

namespace MyWebApi.Api.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class UsersController : ControllerBase { 
        [HttpGet]
        // public dynamic Get(){
        //     return "唯独你没懂";
        // }

        [HttpGet]
        public IEnumerable<dynamic> Get(){
           var users = GetUsers();
           return users;
        }
        [HttpGet("{id}")]
        public dynamic Get(int id){
           var users = GetUsers();
           var user = users.Where(x=>x.Id==id).FirstOrDefault();
           return user;
        }


        [HttpPost]
        public dynamic Post(dynamic model){

            return new{
                Data=model,
                Msg="成功了" 
            };
        }

        [HttpPut("{id}")]
        public dynamic Put(int id,dynamic model){

            return new{
                Data=model,
                Msg=string.Format("要修改的Id为{0},",id) 
            };
        }

        [HttpDelete("{id}")]
        public dynamic Delete(int id,dynamic model){

            return new{
                Data=model,
                Msg=string.Format("要删除的Id为{0},",id) 
            };
        }


        private IEnumerable<Users> GetUsers(){
             var users = new List<Users>{
                new Users{
                    Id=1,
                    UserName="你好",
                    PassWord="确实好啊"
                },
                new Users{
                    Id=2,
                    UserName="真的吗",
                    PassWord="不啊"
                },
                new Users{
                    Id=3,
                    UserName="可以吗",
                    PassWord="我觉得不行"
                },
            };
            return users;
        }
    }
}
